﻿<?php

require_once '../include/common.inc.php';
require_once '../include/upfile.class.php';


/*$sql="DELETE FROM p_leather";
if($db->query($sql))
{*/
 
	$sql = "SELECT `id`,`fabricshown` FROM `product` ";
	$query = $db->query($sql);
	$product_arr=array();
	while($rs=$db->fetch_array($query))
	{
	
	  if(trim($rs['fabricshown'])!="")
	  {
	    $product_arr[]=$rs;	
	  }
	}

	
	$fabric_arr=array();
	$fabric_has_id=array();
	$sql = "SELECT `id`, `name`,`namezh`,`photo` FROM `p_fabric` ";
	$query = $db->query($sql);
	while($rs = $db->fetch_array($query)) 
	{
		$fabric_arr[trim(strtolower($rs['name']))] = $rs['id'];	
		$fabric_has_id[]=$rs['id'];	
	}
		
	
	
	foreach($product_arr as $k=>$v)
	{
	  $v['fabricshown'] = strtolower(trim($v['fabricshown'])); 
	 if($v['fabricshown']!='')
	 {
	    //echo 	$v['id']."_".$v['leathershown']."<br/>";
	  $leather_id =0;
	 if(!array_key_exists($v['fabricshown'],$fabric_arr))
	 {	     
		    $sql4 = "INSERT INTO `p_fabric` (`name`,`creatdate`) VALUES('".$v['fabricshown']."','".time()."');";			
			$db->query($sql4);			
			$fabric_id = $fabric_arr[$v['fabricshown']] = $db->insert_id();
		}else{
			$fabric_id= $fabric_arr[$v['fabricshown']] ;
	 }
	 
	 
	   $sqlin="update `product` set `fabric_id`=".$fabric_id."  where `id`=".$v['id']." ";
	 
	   echo $db->query($sqlin)."<br/>";
	   //echo $sqlin."<br/>";
	   
	 }
	 // $db->query($sqlin);
	  //echo $db->query($sqlin)."<br/>";
	}
//}
//echo $sql_all_num;
?>